// pages/card/card_list.js
var app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    navList: [{
        id: 0,
        name: '全部'
      },
      {
        id: 1,
        name: '激活'
      },
      {
        id: 2,
        name: '获得'
      },
    ],

    navNum: 0
  },

  bindNav(e) {
    var id = e.currentTarget.dataset.id;
    this.setData({
      navNum: id
    })
    this.getAllOrder()
  },

  getAllOrder(e) {
    const that = this;
    wx.showLoading({
      title: '玩命加载中',
      mask: true,
    })
    wx.request({
      url: app.globalData.url + 'CardRecord',
      data: {
        uid: app.globalData.uid,
        record: that.data.navNum,
      },
      method: 'POST',
      success: function (res) {
        wx.hideLoading()
        if (res.data.info) {
          if (res.data.info.card.length == 0) {
            wx.showToast({
              title: '暂无纪录',
              duration: 1500,
              icon: "loading",
              mask: true,
            })
          }
          that.setData({
            info: res.data.info,
          })
        }
      },
    })
   
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    if (app.globalData.uid) {
      needUid();
    } else {
      app.idCB = function (res) {
        needUid();
      }
    }

    function needUid() {
      wx.showLoading({
        title: '玩命加载中',
        mask: true,
      })
      wx.request({
        url: app.globalData.url + 'CardRecord',
        data: {
          uid: app.globalData.uid,
          record: that.data.navNum,
        },
        method: 'POST',
        success: function (res) {
          wx.hideLoading()
          if (res.data.info) {
            if (res.data.info.card.length == 0) {
              wx.showToast({
                title: '暂无纪录',
                duration: 1500,
                icon: "loading",
                mask: true,
              })
            }
            that.setData({
              info: res.data.info,
            })
          }
        },
      })
      if (options.shareNum == 1) {
        wx.showLoading({
          title: '玩命加载中',
          mask: true,
        })
        wx.request({
          url: app.globalData.url + 'GetshareRecharge',
          data: {
            uid: app.globalData.uid,
            id: options.getid,
          },
          method: 'POST',
          success: function (res) {
            wx.hideLoading()
            if (res.data.info) {}
          },
        })
      }
    }
    wx.stopPullDownRefresh();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    this.onLoad()
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})